﻿using Afterbunny.ImageMarker.WPF.DTO;
using System.Collections.Generic;

namespace DistributedVisionRunner.Interface
{
    /// <summary>
    /// 由视觉工程师负责实现
    /// </summary>
    /// <typeparam name="TData">
    /// 输入数据的类型
    /// 目前支持byte(单通道和3通道一样时byte), float, short, ushort
    /// </typeparam>
    public interface IVisionProcessor<TData>
    {
        /// <summary>
        /// 处理来自上位机的数据, 并返回结果
        /// </summary>
        /// <param name="data">
        ///     每个元素都是一张图片的数据
        /// </param>
        /// <param name="productType"></param>
        /// <param name="cavityIndex"></param>
        /// <returns></returns>
        ProcessResult Process(List<TData[]> data, string productType, int cavityIndex);

        /// <summary>
        /// 实现加载配置文件的逻辑
        /// </summary>
        /// <param name="fileDir">文件应该储存在这个文件夹, 方便上位机进行管理, 调用此函数前文件夹已经创建好了, 不用重复创建</param>
        /// <returns>
        /// key = 错误的文件
        /// value = 错误的原因
        /// 假如有文件加载错误, 那么返回不为null或空词典, 否则返回null或者空词典
        /// </returns>
        Dictionary<string, FileError> LoadFiles(string fileDir);

        /// <summary>
        /// <see cref="Process"/>返回的数值型变量的名称
        /// </summary>
        string[] RawOutputNames { get; }

        /// <summary>
        /// 是否将来自 <see cref="IVisionProcessor{TData}"/>
        /// 的原始数据先经过补偿服务后才输入<see cref="GetResultType"/>
        /// </summary>
        bool EnableWeighting { get; }

        /// <summary>
        /// 补偿值的名称
        /// </summary>
        string[] WeightNames { get; }

        /// <summary>
        /// 补偿后的值的名称
        /// </summary>
        string[] WeightedOutputNames { get; }

        string Version { get; }
    }

    public enum FileError
    {
        Lost,
        Uninitialized,
        FormatError
    }

    public class ProcessResult
    {
        /// <summary>
        /// 用于显示的图片数据,
        /// 一个元素代表一张图片, 无论是1或3通道
        /// </summary>
        public List<GraphicPayload> DisplayData { get; set; }

        /// <summary>
        /// 输出的数据
        /// </summary>
        public Statistics Statistics { get; set; }
    }

    public class Statistics
    {
        public Dictionary<string, double> FloatResults { get; set; } = new Dictionary<string, double>();
        public Dictionary<string, int> IntegerResults { get; set; } = new Dictionary<string, int>();
        public Dictionary<string, string> TextResults { get; set; } = new Dictionary<string, string>();
    }






}